<link href="<?php echo base_url()?>common/css/public.css" rel="stylesheet" type="text/css" />
<link rel="stylesheet" href="<?php echo base_url()?>common/kindeditor/themes/default/default.css" />
<script type="text/javascript" src="<?php echo base_url()?>common/js/jquery.min.js"></script>
<script type="text/javascript" src="<?php echo base_url()?>common/layer/layer.js"></script>
<script type="text/javascript" src="<?php echo base_url()?>common/js/jquery.form.js"></script>
<script type="text/javascript" src="<?php echo base_url()?>common/js/jquery.validate.js"></script>
<script type="text/javascript" src="<?php echo base_url()?>common/js/jquery.metadata.js"></script>
<script type="text/javascript" src="<?php echo base_url()?>common/js/jquery.validate.messages_cn.js"></script>
<script type="text/javascript" src="<?php echo base_url()?>common/js/validate.js"></script>
<script type="text/javascript" src="<?php echo base_url()?>common/js/validateForm.js"></script>
<script type="text/javascript" src="<?php echo base_url()?>common/js/jquery.Msg.js"></script>
<script src="<?php echo base_url()?>common/kindeditor/kindeditor.js"></script>
<script src="<?php echo base_url()?>common/kindeditor/lang/zh_CN.js"></script>

<script type="text/javascript">
    function add_top_menu() {
        url = "<?php echo site_url('admin/menu/add_top_menu')?>";
        layer.open({
            type: 2,
            title: '栏目添加',
            maxmin: true,
            shadeClose: false,
            area: ['600px', '400px'],
            offset: ['100px', ''],
            content: url,
        });
    }
    function edit_top_menu(menuid) {
        var url = "<?php echo site_url('admin/menu/edit_top_menu/{nid}')?>";
        url = url.replace('{nid}', menuid);
        layer.open({
            type: 2,
            title: '栏目添加',
            maxmin: true,
            shadeClose: false,
            area: ['600px', '400px'],
            offset: ['100px', ''],
            content: url,
        });
    }
    function Success(data) {
        $.Success(data, init);
    }
    var init = function init_page() {
        
        var url = parent.window.location.href;
        if (url.indexOf('?init=1') <= 0) {
            url = url + "?init=1";
        }
        parent.window.location.href = url;
    }

    $(function () {
        $(".tableBasic .form_weight").each(function () {
            var itemsId = $(this).attr('id');
            $.validate_Weight(itemsId);
        });
        $(".tableBasic .form_drop").each(function () {
            var itemsId = $(this).attr('id');
            $.validate_Weight(itemsId);
        });
    });
    function Del(menuid) {
        url = "/admin/menu/del_top_menu/" + menuid;
        layer.confirm("删除此栏目，其所有子集栏目都会删除，确定删除？", function () {
            $.post(url, null, function (data) {
                var jsonData = $.parseJSON(data);
                if (jsonData.Statu == 'ok') {
                    Success(jsonData)
                }
                else {
                    Success(jsonData)
                }
            })
        }, function () {
            layer.msg('取消删除', { icon: 0 });
        })
    }
    function change_drop(obj,menuid)
    {
        url = "/admin/menu/edit_top_menu_drop/" + menuid;
        layer.confirm("删除此栏目，其所有子集栏目都会删除，确定删除？", function () {
            $.post(url, {'drop':$(obj).val()}, function (data) {
                var jsonData = $.parseJSON(data);
                if (jsonData.Statu == 'ok') {
                    Success(jsonData)
                }
                else {
                    Success(jsonData)
                }
            })
        }, function () {
            layer.msg('取消更改', { icon: 0 });
        })
    }

</script>


<div id="dcMain" style="margin-left:0;">
    <div id="manager" class="mainBox" style="height:auto!important;height:550px;min-height:550px;padding: 0 22px 0 22px;">
        <h3>
            <a href="javascript:add_top_menu()" class="actionBtn">添加栏目</a>
        </h3>
        <table width="100%" border="0" cellpadding="8" cellspacing="0" class="tableBasic">
            <tr>
                <th width="50" align="center">编号</th>
                <th align="left">栏目名称</th>
                <th align="left">权重</th>
                <?php if($user_authority==1):?>
                <th align="left">子集下拉</th>
                <?php endif;?>
                <th align="center">操作</th>
            </tr>
            <?php foreach($top_level_menu as $top_level_menu_item):?>
            <tr>
                <td align="center"><?php echo $top_level_menu_item->menuid?></td>
                <td><?php echo $top_level_menu_item->title?></td>
                <td>
                    <form class="form_weight" id="ajax_form_<?php echo $top_level_menu_item->menuid?>" method="post" action="<?php echo site_url('admin/menu/set_menu_weight/'.$top_level_menu_item->menuid)?>?returnurl=<?php echo 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']?>">
                        <input type="text" name="weight" id="<?php echo $top_level_menu_item->menuid?>" value="<?php echo $top_level_menu_item->weight?>" /><input type="submit" value="更新" style="color:#666;width:40px;margin-left:20px;" />
                    </form>
                </td>
                <?php if($user_authority==1):?>
                <td>
                    <select name="isdrop" onchange="change_drop(this,<?php echo $top_level_menu_item->menuid?>)">
                        <option value="1" <?php echo $top_level_menu_item->isdrop==1?'selected="selected"':'' ?>>是</option>
                        <option <?php echo $top_level_menu_item->isdrop==0?'selected="selected"':'' ?> value="0">否</option>
                    </select>
                </td>
                <?php endif;?>
                <td align="center">
                    <a href="javascript:edit_top_menu(<?php echo $top_level_menu_item->menuid?>)">编辑</a>|
                    <a href="javascript:Del(<?php echo $top_level_menu_item->menuid?>)">删除</a>
                </td>
            </tr>
            <?php endforeach;?>
        </table>
    </div>
</div>